package com.ztesoft.web.cleanup.service.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.stereotype.Service;

import com.ztesoft.core.db.ds.DynamicDataSourceManager;
import com.ztesoft.core.idproduce.ISequenceGenerator;
import com.ztesoft.framework.exception.BaseAppException;
import com.ztesoft.framework.exception.ExceptionHandler;
import com.ztesoft.framework.log.ZTEsoftLogManager;
import com.ztesoft.framework.util.DateUtils;
import com.ztesoft.framework.util.Utils;
import com.ztesoft.web.baseconfig.db.arg.DmTargetTableArg;
import com.ztesoft.web.baseconfig.db.arg.TargetColMapArg;
import com.ztesoft.web.baseconfig.db.dao.DmSrcTableDao;
import com.ztesoft.web.baseconfig.db.dao.DmTableRelDao;
import com.ztesoft.web.baseconfig.db.dao.DmTargetTableDao;
import com.ztesoft.web.baseconfig.db.dao.TargetColMapDao;
import com.ztesoft.web.baseconfig.db.po.DmSrcTablePO;
import com.ztesoft.web.baseconfig.db.po.DmTableRelPO;
import com.ztesoft.web.baseconfig.db.po.DmTargetTablePO;
import com.ztesoft.web.baseconfig.db.po.TargetColMapPO;
import com.ztesoft.web.cleanup.service.CleanUpTaskService;
import com.ztesoft.web.common.DMSConstant;
import com.ztesoft.web.common.SubTableDefine;
import com.ztesoft.web.common.customdb.SQLHelper;
import com.ztesoft.web.common.customdb.dao.dto.DmTaskStageDto;
import com.ztesoft.web.common.db.dao.DmDao;
import com.ztesoft.web.common.db.dao.DmSecondaryStageDao;
import com.ztesoft.web.common.db.po.DmPO;
import com.ztesoft.web.common.db.po.DmSecondaryStagePO;
import com.ztesoft.web.syncbaseinfo.service.BaseInfoService;

/**
 * 清理处理
 * 
 * @author lin.weibin@zte.com.cn
 * @date 2015年8月11日
 */
@Service("CleanUpTaskServiceImpl")
public class CleanUpTaskServiceImpl implements CleanUpTaskService {
	
	private static final ZTEsoftLogManager LOGGER = ZTEsoftLogManager.getLogger(CleanUpTaskServiceImpl.class);

	@Autowired
	private DynamicDataSourceManager dynamicDataSourceManager;
	
	@Autowired
	private DmTableRelDao tableRelDao;
	
	@Autowired
	private BaseInfoService baseInfoService;
	
	@Autowired
	private DmDao dmDao;
	
	@Autowired
	private SubTableDefine subTableDefine;
	
	@Autowired
	private DmSrcTableDao dmSrcTableDao;
	
	@Autowired
	private DmSecondaryStageDao dmSecondaryStageDao;
	
	@Resource(name = "sequenceProcGenerator")
	private ISequenceGenerator sequenceGenerator;
	
	@Autowired
	private DmTargetTableDao targetTableDao;
	
	@Autowired
	private TargetColMapDao targetColMapDao;
	
	@Override
	public int addCleanUp(Integer stage, List<DmPO> dmPOList, List<DmSecondaryStagePO> secondaryStagePOList, List<DmSrcTablePO> refList,
			DmSrcTablePO srcTablePO, DmTaskStageDto taskStagePO, int dloop, String[] dbConfig) throws BaseAppException {
		int record = 0;
		LOGGER.info("{0} 4、根据从表表名顺序依次获取从表与主表的关联关系执行清理动作",Thread.currentThread());
		DataSource dataSource = null;
		DmTargetTablePO targetPO = null;//目标对象
		String clearTableName = srcTablePO.getTableName();//默认清理源，如果清理目标重新赋值
		if (stage == null) {//正常流程~
			dataSource = dynamicDataSourceManager.getDruidDataSource(srcTablePO.getDbLinkId()+srcTablePO.getDbUserName(), 
					dbConfig);
		} else {//清理目标
			DmTargetTableArg dmTargetTableArg = new DmTargetTableArg();
			DmTargetTableArg.DmTargetTableCriteria targetTableCriteria = dmTargetTableArg.createCriteria();
			targetTableCriteria.andSourceDataIdEqualTo(srcTablePO.getSourceDataId());
			targetPO = targetTableDao.selectByArg(dmTargetTableArg).get(0);
			clearTableName = targetPO.getTableName();// 
			dbConfig = baseInfoService.getDbConfig(targetPO.getDbLinkId(), targetPO.getDbUserName());
			dataSource = dynamicDataSourceManager.getDruidDataSource(targetPO.getDbLinkId()+targetPO.getDbUserName(), 
					dbConfig);
		}
		LOGGER.debug(Thread.currentThread()+"获取链接信息ok...");
		
		Connection conn = null;
		PreparedStatement ps = null;
		Connection connRef = null;
		PreparedStatement psRef = null;
		DataSource dsRef = null;
		/**
		 * 数据类型~
		 */
		Map<String,Integer> dataTypeMap = null;

		try {
			conn = DataSourceUtils.getConnection(dataSource);
			conn.setAutoCommit(false);
			StringBuilder sqlBuilder = null;
			StringBuilder secondarySqlBuilder = null;
			String[] keyNames = null;
			String[] keyValues = null;
			List<String> vList;
			DmTableRelPO tableRefPO;
			String relMapCols = null;
			String[] subMapCols;
			/*
			 * 
			 */
			if (!Utils.isEmpty(secondaryStagePOList)) {//从表名集合
				LOGGER.info(Thread.currentThread()+"\r\n分支：有体检-备份-清理环节的处理");
				String[] dbConfigRef = null;
				DmPO refDmPO;
				DmSrcTablePO srdSrcTablePO;
				DmTargetTablePO srdTargetPO = null;//从表の目标表
				String srdTableName = null;
				Map<String, List<DmPO>> dmListMap = new HashMap<String, List<DmPO>>();
				if (stage == null) {//正常流程
					dmListMap.put(dmPOList.get(0).getDmObjectName(), dmPOList);
				} else if (targetPO != null && "T".equals(targetPO.getSubFlag())) {//目标分表
					List<DmPO> tempList;
					for (int k = 0; k < dmPOList.size(); k++) {//主表明细
						refDmPO  = dmPOList.get(k);
						if (dmListMap.keySet().contains(refDmPO.getDmTargetTableName())) {
							dmListMap.get(refDmPO.getDmTargetTableName()).add(refDmPO);
						} else {
							tempList = new ArrayList<DmPO>();
							tempList.add(refDmPO);
							dmListMap.put(refDmPO.getDmTargetTableName(), tempList);
						}
					}
				} else if (targetPO != null && "F".equals(targetPO.getSubFlag())) {//目标不分表
					dmListMap.put(dmPOList.get(0).getDmTargetTableName(), dmPOList);
				} 
				
				for (DmSecondaryStagePO secondaryStagePO :secondaryStagePOList) {
					if (stage == null) {//清理
						srdSrcTablePO = dmSrcTableDao.selectByPrimaryKey(secondaryStagePO.getSourceDataId());
						srdTableName = srdSrcTablePO.getTableName();
						dbConfigRef = baseInfoService.getDbConfig(srdSrcTablePO.getDbLinkId(), srdSrcTablePO.getDbUserName());
						dsRef = dynamicDataSourceManager.getDruidDataSource(srdSrcTablePO.getDbLinkId()+srdSrcTablePO.getDbUserName(), dbConfigRef);
					} else {//清理目标
						DmTargetTableArg dmTargetTableArg = new DmTargetTableArg();
						DmTargetTableArg.DmTargetTableCriteria targetTableCriteria = dmTargetTableArg.createCriteria();
						targetTableCriteria.andSourceDataIdEqualTo(secondaryStagePO.getSourceDataId());
						srdTargetPO = targetTableDao.selectByArg(dmTargetTableArg).get(0);
						srdTableName = srdTargetPO.getTableName();
						dbConfigRef = baseInfoService.getDbConfig(srdTargetPO.getDbLinkId(), srdTargetPO.getDbUserName());
						dsRef = dynamicDataSourceManager.getDruidDataSource(srdTargetPO.getDbLinkId()+srdTargetPO.getDbUserName(), dbConfigRef);
					}
					
					/*
					 * 
					 */
					if("oracle".equalsIgnoreCase(dbConfigRef[0])){
						dataTypeMap = getDataType(dsRef, srdTableName);
					}
					LOGGER.info(Thread.currentThread()+"||获取数据库连接中...");
					connRef = DataSourceUtils.getConnection(dsRef);
					LOGGER.info(Thread.currentThread()+"获取链接信息ok...");
					connRef.setAutoCommit(false);
					int[] ii = null;
					String tableName = null;
					for (Entry<String, List<DmPO>> dmEntryList : dmListMap.entrySet()) {
						tableName = dmEntryList.getKey();
						dmPOList = dmEntryList.getValue();
						for (int k = 0; k < dmPOList.size(); k++) {//主表明细
							refDmPO = dmPOList.get(k);
							keyNames = refDmPO.getDmObjectKeyName().split(",");//主表关键字段名
							keyValues = refDmPO.getDmObjectKeyValue().split(",");//主表关键字段值
							if (k == 0) {
								tableRefPO = tableRelDao.selectBySourceDataId(secondaryStagePO.getSourceDataId());
								relMapCols = tableRefPO.getRelMapCols();//关联主表关键字段名
								subMapCols = tableRefPO.getSubMapCols().split(",");//从表关键字段名
								String sql = "";
								secondarySqlBuilder = new StringBuilder(" delete from ");
								if (stage == null) {//正常流程~							
									secondarySqlBuilder.append(secondaryStagePO.getCheckObjName()).append(" where ");;
									for (int i = 0; i < subMapCols.length; i++) {
										 if (i != 0) {
											 secondarySqlBuilder.append(" and ");
								         }
										secondarySqlBuilder.append(subMapCols[i]).append(" = ? ");
									}
								} else {//					
									/*
									 * 目标清理，
									 * 
									 */
									/*
									 * 字段映射
									 */
									TargetColMapArg arg = new TargetColMapArg();
									TargetColMapArg.TargetColMapCriteria cri = arg.createCriteria();
									cri.andSourceDataIdEqualTo(secondaryStagePO.getSourceDataId());
									cri.andTargetDataIdEqualTo(srdTargetPO.getTargetDataId());
									List<TargetColMapPO> colMapList = targetColMapDao.selectByArg(arg);
									Map<String, TargetColMapPO> map = new HashMap<String, TargetColMapPO>();
									for (TargetColMapPO targetColMapPO : colMapList) {										
										map.put(targetColMapPO.getSourceColumn().toUpperCase(), targetColMapPO);
									}
									secondarySqlBuilder.append(tableName).append(" where ");;
									for (int i = 0; i < subMapCols.length; i++) {
										 if (i != 0) {
											 secondarySqlBuilder.append(" and ");
								         }
										secondarySqlBuilder.append(map.get(subMapCols[i].toUpperCase()).getTargetColumn()).append(" = ? ");
									}
								}
								sql = secondarySqlBuilder.toString();
								LOGGER.info(Thread.currentThread()+"从表SQL："+sql);
								psRef = conn.prepareStatement(sql);
							}
							
							/*
							 *4.0、查出关联关系 
							 */
							vList = new ArrayList<String>();
							for (int i = 0, j = keyNames.length; i < j; i++) {
								if (relMapCols.contains(keyNames[i])) {
									vList.add(keyValues[i]);
								}
							}
							SQLHelper.setValue(psRef, vList, dbConfigRef[0],dataTypeMap,relMapCols);
							psRef.addBatch();
						}
						ii = psRef.executeBatch();
					}
					//更新从表处理数据
					if (stage == null) {							
						dmSecondaryStageDao.updateSecondaryStageCount(ii.length, 
								dmSrcTableDao.selectByPrimaryKey(secondaryStagePO.getSourceDataId()).getOneRecordSize(), 
								secondaryStagePO.getDmSecondaryInfoId());
					}
				}
			}
			
			/*
			 * 
			 */
			if (!Utils.isEmpty(refList)) {//关联从表
				LOGGER.info(Thread.currentThread()+"\r\n分支：只有体检-清理环节的处理");
				String[] dbConfigRef = null;
				DmPO refDmPO;
				String refTableName = "";
				int idloop = 0;
				Integer[] ids = getIds();
				for (DmSrcTablePO ref :refList) {

					dbConfigRef = baseInfoService.getDbConfig(ref.getDbLinkId(), ref.getDbUserName());
					dsRef = dynamicDataSourceManager.getDruidDataSource(ref.getDbLinkId()+ref.getDbUserName(), dbConfigRef);
					LOGGER.info(Thread.currentThread()+"||获取数据库连接中...");
					connRef = DataSourceUtils.getConnection(dsRef);
					LOGGER.info(Thread.currentThread()+"获取链接信息ok...");
					connRef.setAutoCommit(false);
					DmSecondaryStagePO dmSecondaryStagePO = null;
					for (int k = 0; k < dmPOList.size(); k++) {//主表明细
						refDmPO  = dmPOList.get(k);
						keyNames = refDmPO.getDmObjectKeyName().split(",");//主表关键字段名
						keyValues = refDmPO.getDmObjectKeyValue().split(",");//主表关键字段值
						if ("0".equals(ref.getSubFlag())) {
							refTableName = ref.getTableName();
						} else if ("1".equals(ref.getSubFlag())) {						
							refTableName = subTableDefine.generateRefTableName(ref.getSourceDataId(), keyNames, keyValues);
						}
						if (k == 0) {
							LOGGER.info(Thread.currentThread()+"4.0.0、查询出具体从表表名refTableName：{0}",refTableName);
							dataTypeMap = getDataType(dsRef, refTableName);
						}
						/*
						 * 4.0.1、更新从表环节执行状态00R
						 * dloop用于限制只查询一次是否存在从表环节，如果存在则更新，否则创建一条记录
						 */
						if (dloop == 1) {//
							java.util.Date createDate = DateUtils.getDBCurrentTime();
							dmSecondaryStagePO = new DmSecondaryStagePO();
							dmSecondaryStagePO.setCheckObjName(refTableName);
							dmSecondaryStagePO.setDmTaskId(taskStagePO.getDmTaskId());
							dmSecondaryStagePO.setDmStrategyId(taskStagePO.getDmStrategyId());
							dmSecondaryStagePO.setDmInfoId(taskStagePO.getDmInfoId());
							dmSecondaryStagePO = dmSecondaryStageDao.selectByRecord(dmSecondaryStagePO);
							if (null == dmSecondaryStagePO) {
								dmSecondaryStagePO = new DmSecondaryStagePO();
								dmSecondaryStagePO.setDmSecondaryInfoId(ids[idloop]);			
								idloop = idloop + 1;
								if (idloop > 5) {//超过5重新获取
									ids = getIds();
									idloop = 0;
								}
								dmSecondaryStagePO.setDmTaskId(taskStagePO.getDmTaskId());
								dmSecondaryStagePO.setDmStrategyId(taskStagePO.getDmStrategyId());
								dmSecondaryStagePO.setDmInfoId(taskStagePO.getDmInfoId());
								dmSecondaryStagePO.setSourceDataId(ref.getSourceDataId());
								dmSecondaryStagePO.setCheckObjName(refTableName);
								dmSecondaryStagePO.setStage(DMSConstant.STAGE_CLEANUP);
								dmSecondaryStagePO.setState(/*DMSConstant.Status.PROCESSING.toString()*/"00T");
								dmSecondaryStagePO.setStateDate(createDate);
								dmSecondaryStagePO.setTaskStartTime(createDate);
								dmSecondaryStagePO.setTaskEndTime(null);
								dmSecondaryStagePO.setCreateDate(createDate);
								dmSecondaryStagePO.setNodeId(taskStagePO.getNodeId());
								dmSecondaryStageDao.insert(dmSecondaryStagePO);
							}else {
								dmSecondaryStagePO.setTaskStartTime(createDate);
								dmSecondaryStagePO.setState(/*DMSConstant.Status.PROCESSING.toString()*/"00T");
								dmSecondaryStagePO.setStateDate(createDate);
								dmSecondaryStageDao.updateByPrimaryKeySelective(dmSecondaryStagePO);
							}
						}
						
						/*
						 *4.0.2、查出关联关系 
						 */
						if (k == 0) {	//构建一次						
							tableRefPO = tableRelDao.selectBySourceDataId(ref.getSourceDataId());
							relMapCols = tableRefPO.getRelMapCols();//关联主表关键字段名
							subMapCols = tableRefPO.getSubMapCols().split(",");//从表关键字段名
							
							secondarySqlBuilder = new StringBuilder(" delete from ");
							secondarySqlBuilder.append(refTableName).append(" where ");;
							
							for (int i = 0; i < subMapCols.length; i++) {
//									sqlType = baseInfoService.getColumnType(srcTablePO.getSourceDataId(), subMapCols[i]);
								if (i != 0) {
									secondarySqlBuilder.append(" and ");
					            }
								secondarySqlBuilder.append(subMapCols[i]).append(" = ? ");
							}
							String sql = secondarySqlBuilder.toString();
							LOGGER.info(Thread.currentThread()+"从表SQL："+sql);
							psRef = connRef.prepareStatement(sql);
						}
						
						vList = new ArrayList<String>();
						for (int i = 0, j = keyNames.length; i < j; i++) {
							if (relMapCols.contains(keyNames[i])) {
								vList.add(keyValues[i]);
							}
						}
						SQLHelper.setValue(psRef, vList, dbConfigRef[0],dataTypeMap,relMapCols);
						psRef.addBatch();
					}
					int[] ii = psRef.executeBatch();
					
					/*
					 * 
					 * 4.0.3、更新从表环节处理记录
					 * 不是第一批次需要先查询、再作更新
					 */
					if (null == dmSecondaryStagePO) {
						dmSecondaryStagePO = new DmSecondaryStagePO();
						dmSecondaryStagePO.setCheckObjName(refTableName);
						dmSecondaryStagePO.setDmTaskId(taskStagePO.getDmTaskId());
						dmSecondaryStagePO.setDmStrategyId(taskStagePO.getDmStrategyId());
						dmSecondaryStagePO.setDmInfoId(taskStagePO.getDmInfoId());
						dmSecondaryStagePO = dmSecondaryStageDao.selectByRecord(dmSecondaryStagePO);
					}
					dmSecondaryStageDao.updateSecondaryStageCount(ii.length, //
							dmSrcTableDao.selectByPrimaryKey(dmSecondaryStagePO.getSourceDataId()).getOneRecordSize(), 
							dmSecondaryStagePO.getDmSecondaryInfoId());
				}
				
			}
			
			/*
			 * 5、处理主表记录
			 */
			LOGGER.info(Thread.currentThread()+"处理主表记录");
			DmPO refDmPO = null;
			String tableName = null;
			Map<String, List<DmPO>> dmListMap = new HashMap<String, List<DmPO>>();
			if (stage == null) {//正常流程
				dmListMap.put(dmPOList.get(0).getDmObjectName(), dmPOList);
			} else if (targetPO != null && "T".equals(targetPO.getSubFlag())) {//目标分表
				List<DmPO> tempList;
				for (int k = 0; k < dmPOList.size(); k++) {//主表明细
					refDmPO  = dmPOList.get(k);
					if (dmListMap.keySet().contains(refDmPO.getDmTargetTableName())) {
						dmListMap.get(refDmPO.getDmTargetTableName()).add(refDmPO);
					} else {
						tempList = new ArrayList<DmPO>();
						tempList.add(refDmPO);
						dmListMap.put(refDmPO.getDmTargetTableName(), tempList);
					}
				}
			} else if (targetPO != null && "F".equals(targetPO.getSubFlag())) {//目标不分表
				dmListMap.put(targetPO.getTableName(), dmPOList);
			} 
			
			for (Entry<String, List<DmPO>> dmEntryList : dmListMap.entrySet()) {
				tableName = dmEntryList.getKey();
				dmPOList = dmEntryList.getValue();
				LOGGER.info("{0}批次清理表{1}",Thread.currentThread(), tableName);
				for (int k = 0; k < dmPOList.size(); k++) {//主表明细
					refDmPO  = dmPOList.get(k);
					keyValues = refDmPO.getDmObjectKeyValue().split(",");//主表关键字段值
					if (k == 0) {
						dataTypeMap = getDataType(dataSource, clearTableName);
						keyNames = refDmPO.getDmObjectKeyName().split(",");//主表关键字段名					
						sqlBuilder = new StringBuilder(" delete from ");
						
						if (stage == null) {//正常流程~	
							sqlBuilder.append(tableName).append(" where ");
							for (int i = 0; i < keyNames.length; i++) {
					            if (i != 0) {
					                sqlBuilder.append(" and ");
					            }
								sqlBuilder.append(keyNames[i]).append(" = ? ");
							}
						} else {//					
							/*
							 * 字段映射
							 */
							TargetColMapArg arg = new TargetColMapArg();
							TargetColMapArg.TargetColMapCriteria cri = arg.createCriteria();
							cri.andSourceDataIdEqualTo(srcTablePO.getSourceDataId());
							cri.andTargetDataIdEqualTo(targetPO.getTargetDataId());
							List<TargetColMapPO> colMapList = targetColMapDao.selectByArg(arg);
							Map<String, TargetColMapPO> map = new HashMap<String, TargetColMapPO>();
							for (TargetColMapPO targetColMapPO : colMapList) {										
								map.put(targetColMapPO.getSourceColumn().toUpperCase(), targetColMapPO);
							}
							sqlBuilder.append(tableName).append(" where ");;
							for (int i = 0; i < keyNames.length; i++) {
					            if (i != 0) {
					                sqlBuilder.append(" and ");
					            }
								sqlBuilder.append(map.get(keyNames[i].toUpperCase()).getTargetColumn()).append(" = ? ");
							}
						}
						String sql = sqlBuilder.toString();
						LOGGER.info(Thread.currentThread()+"主表SQL："+sql);
						ps = conn.prepareStatement(sql);
					}
					// add++
					SQLHelper.setValue(ps, keyValues, dbConfig[0],dataTypeMap,keyNames);
					ps.addBatch();
				}
				int[] ii = ps.executeBatch();
				record = record + ii.length;
			}
			if (connRef!=null) {				
				connRef.commit();
			}
			conn.commit();
		} catch (Exception e){
			LOGGER.error("执行清理异常",e);
			if (connRef!=null) {					
				try {
					connRef.rollback();
				} catch (SQLException e2) {
				}
			}
			try {
				conn.rollback();
			} catch (SQLException e1) {
			}
			throw ExceptionHandler.publish("执行清理异常"+e.toString());
		} finally {
			JdbcUtils.closeStatement(psRef);
			DataSourceUtils.releaseConnection(connRef, dsRef);
			JdbcUtils.closeStatement(ps);
			DataSourceUtils.releaseConnection(conn, dataSource);
		}
		return record;
	}


	/**
	 * 获取字段类型
	 * @param bds
	 * @param tableName
	 * @return
	 * @throws SQLException
	 */
	private Map<String, Integer> getDataType(DataSource bds, String tableName) throws SQLException {
		Map<String, Integer> dataTypeMap = new HashMap<String, Integer>();
		String sql = "select * from "+tableName+" where 1=0";
		Connection conn = null;
		java.sql.Statement stmt = null;
		ResultSet columns = null;
		ResultSetMetaData rsmd = null;
		try {
			conn = DataSourceUtils.getConnection(bds);
			stmt = conn.createStatement();
			columns = stmt.executeQuery(sql);
			rsmd = columns.getMetaData();  
			for(int i=1;i<=rsmd.getColumnCount();i++){
				dataTypeMap.put(rsmd.getColumnName(i).toLowerCase(), rsmd.getColumnType(i));
			}
		} /*catch (Exception e) {
			// : handle exception
		} */finally {
			JdbcUtils.closeStatement(stmt);
			JdbcUtils.closeResultSet(columns);
			DataSourceUtils.releaseConnection(conn, bds);
		}
		return dataTypeMap;
	}

	/**
	 * 获取主键ID
	 * @return
	 * @throws BaseAppException 
	 */
	private Integer[] getIds() throws BaseAppException {
//		Integer[] ids = new Integer[5];
//		ids = sequenceGenerator.sequenceBatchIntValue("DM_SECONDARY_STAGE","DM_SECONDARY_INFO_ID", 5);
//		return ids;
		return sequenceGenerator.sequenceBatchIntValue("DM_SECONDARY_STAGE","DM_SECONDARY_INFO_ID", 5);
	}

}

